<?php

namespace app\controller;

use Exception;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Db;
use think\helper\Str;
use mikkle\tp_aliyun\SendSms;

class SendMsgController
{

    protected $msg;

    public function __construct()
    {
        $config = [
            'AccessKeyId' => 'LTAI4FxVY2GM19PMKuG7fYVb',
            'AccessSecret' => 'rcaCWfLRUoWZZPmUjZXNXTa4etLGAJ',
            'TemplateCode' => 'SMS_176010400',
            'SignName' => '猫易查',
        ];
        $this->msg = new SendSms($config);
    }

    /**
     * 发送验证码
     * @param $mobile
     * @param $msg
     *
     * @return bool
     */
    public function sendCode($mobile,$msg)
    {
        $ret = $this->msg->send($mobile, $msg);
        $data['mobile'] = $mobile;
        $data['content'] = $msg;
        $data['create_time'] = toDate(time());
        $data['results'] = json_encode($ret, JSON_UNESCAPED_UNICODE);
        Db::name('msg')->save($data);
        return $ret->Code =='OK' ? true: false;
    }
}
